package com.example.petcare.mapper;

import com.example.petcare.pojo.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface GoodsMapper {

    // 添加增值商品
    @Insert("INSERT INTO goods (name, description, cover_image, price,  is_on_sale,  provider_id) " +
            "VALUES (#{name}, #{description}, #{coverImage}, #{price}, #{isOnSale},  #{providerId})")
    void addGoods(Goods goods);

    // 修改增值商品
    @Update("UPDATE goods SET name = #{name}, description = #{description}, cover_image = #{coverImage}, " +
            "price = #{price}, is_on_sale = 0 ,audit_status=0 WHERE g_id = #{gId}")
    void updateGoods(Goods goods);

    // 查看增值商品列表
    @Select("SELECT * FROM goods WHERE provider_id = #{providerId}")
    List<Goods> list(Integer providerId);

    // 删除增值商品
    @Delete("DELETE FROM goods WHERE g_id = #{gId}")
    void deleteGoods(Integer gId);


    // 根据ID查询增值商品
    @Select("SELECT * FROM goods WHERE g_id = #{gId}")
    Goods findById(Integer gId);

    // 修改商品上下架状态
    @Update("UPDATE goods SET is_on_sale = #{isOnSale} WHERE g_id = #{gId}")
    void updateGoodsStatus(Integer gId, Boolean isOnSale);
}
